package com.xzan.medusaweb.controller.stockstrategy;

import com.xzan.medusa.common.entity.AppBizResult;
import com.xzan.medusa.common.form.stock.StockStrategyForm;
import com.xzan.medusa.common.util.GsonUtils;
import com.xzan.medusa.core.StockUtil;
import com.xzan.medusa.core.ao.StockStrategyAO;
import com.xzan.medusaweb.ws.MedusaWebSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/stock")
@Slf4j
public class StockStrategyController {
    @Autowired
    private StockStrategyAO stockStrategyAO;
    @Autowired
    private MedusaWebSocket medusaWebSocket;
    @RequestMapping("addstrategy.do")
    public String addStockStrategy(StockStrategyForm stockStrategyForm){
        return "views/strategy/add";
    }
    @RequestMapping("/add.do")
    @ResponseBody
    public String saveStockStrategy(StockStrategyForm stockStrategyForm) {
        log.info("add saveStockStrategy strategy:{}", stockStrategyForm);
        AppBizResult<Boolean> appBizResult = stockStrategyAO.addStockStrategy(stockStrategyForm);
        return GsonUtils.toJsonString(appBizResult);
    }
    @RequestMapping("/getStockInfo.do")
    @ResponseBody
    public String getStockInfo(StockStrategyForm stockStrategyForm){
        log.info("code:{}",stockStrategyForm.getCode());
        return StockUtil.getStockName(stockStrategyForm.getCode());

    }
}
